package com.ruoyi.project.platform.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.project.platform.domain.PltUserApi;
import com.ruoyi.project.platform.service.IPltUserApiService;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.page.TableDataInfo;

/**
 * 用户apikeyController
 * 
 * @author ruoyi
 * @date 2020-07-27
 */
@RestController
@RequestMapping("/platform/api")
public class PltUserApiController extends BaseController
{
    @Autowired
    private IPltUserApiService pltUserApiService;

    /**
     * 查询用户apikey列表
     */
    @PreAuthorize("@ss.hasPermi('platform:api:list')")
    @GetMapping("/list")
    public TableDataInfo list(PltUserApi pltUserApi)
    {
        startPage();
        List<PltUserApi> list = pltUserApiService.selectPltUserApiList(pltUserApi);
        return getDataTable(list);
    }

    /**
     * 导出用户apikey列表
     */
    @PreAuthorize("@ss.hasPermi('platform:api:export')")
    @Log(title = "用户apikey", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PltUserApi pltUserApi)
    {
        List<PltUserApi> list = pltUserApiService.selectPltUserApiList(pltUserApi);
        ExcelUtil<PltUserApi> util = new ExcelUtil<PltUserApi>(PltUserApi.class);
        return util.exportExcel(list, "api");
    }

    /**
     * 获取用户apikey详细信息
     */
    @PreAuthorize("@ss.hasPermi('platform:api:query')")
    @GetMapping(value = "/{apiId}")
    public AjaxResult getInfo(@PathVariable("apiId") Long apiId)
    {
        return AjaxResult.success(pltUserApiService.selectPltUserApiById(apiId));
    }

    /**
     * 新增用户apikey
     */
    @PreAuthorize("@ss.hasPermi('platform:api:add')")
    @Log(title = "用户apikey", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PltUserApi pltUserApi)
    {
        return toAjax(pltUserApiService.insertPltUserApi(pltUserApi));
    }

    /**
     * 修改用户apikey
     */
    @PreAuthorize("@ss.hasPermi('platform:api:edit')")
    @Log(title = "用户apikey", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PltUserApi pltUserApi)
    {
        return toAjax(pltUserApiService.updatePltUserApi(pltUserApi));
    }

    /**
     * 删除用户apikey
     */
    @PreAuthorize("@ss.hasPermi('platform:api:remove')")
    @Log(title = "用户apikey", businessType = BusinessType.DELETE)
	@DeleteMapping("/{apiIds}")
    public AjaxResult remove(@PathVariable Long[] apiIds)
    {
        return toAjax(pltUserApiService.deletePltUserApiByIds(apiIds));
    }
}
